package org.dyr.team02.recruit.web;

import java.io.File;
import java.io.IOException;

import javax.annotation.Resource;

import org.dyr.team02.recruit.bean.TestUser;
import org.dyr.team02.recruit.service.TestUserService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

@Controller
public class TestUserController {
	
	@Resource
	private TestUserService testUserService;
	
	@RequestMapping(value="/view",method=RequestMethod.GET)
	public String page(){
		return "testpage";
	}
	
	@RequestMapping(value="/form",method=RequestMethod.POST)
	public void form(TestUser testUser){
		System.out.println(testUser);
		System.out.println(testUserService.login(testUser));
	}
	
	@RequestMapping(value="/file",method=RequestMethod.POST)
	public void file(MultipartFile file) throws IllegalStateException, IOException{
		System.out.println(file.getOriginalFilename());
		file.transferTo(new File("e:/"+file.getOriginalFilename()));
	}
	
	@RequestMapping(value="/ajax",method=RequestMethod.POST)
	@ResponseBody
	public TestUser ajax(@RequestBody TestUser testUser){
		System.out.println(testUser);
		return testUserService.login(testUser);
	}
}
